home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / uw_1.exe / UW_TUT7.C < prev    next >
Text File  |  1992-11-02  |  17KB  |  444 lines

  1. /****************************************************************************/
  2. /* UW_TUT7.C                                                                */
  3. /*                                                                          */
  4. /* NOTE: THIS FILE IS PUBLIC DOMAIN AND MAY BE MODIFIED AND USED AT WILL    */
  5. /*                                                                          */
  6. /* Now we add background printing, allowing us to print a single record     */
  7. /* or all of the records.  We will add another drop down menu to do this.   */
  8. /* Since we are already calling a background function to display the real-  */
  9. /* time clock, we cannot set the idle function to print.  However, we can   */
  10. /* simply let the current idle function, "disp_time", call "print_in_bkgrnd"*/
  11. /* Using this simple method, we can perform many tasks in the background!   */
  12. /*   Notice that we print to LPT1 and make no arrangements for DOS critical */
  13. /* errors!  We are  trying to show the use of the library as opposed to     */
  14. /* ideal guidelines for application development and don't want to complicate*/
  15. /* this mini-app.                                                           */
  16. /*                                                                          */
  17. /*                                                         Dr. Boyd Gafford */
  18. /*                                                         Kevin Huck       */
  19. /*                                                         EnQue Software   */
  20. /*                                                         09/11/92         */
  21. /****************************************************************************/
  22. #include <stdio.h>
  23. #include <fcntl.h>
  24. #include <io.h>
  25. #ifndef __TURBOC__
  26. #include <sys\types.h>
  27. #endif
  28. #include <sys\stat.h>
  29. #include <time.h>
  30. #include <ctype.h>
  31. #include "uw.h"                           /* include the necessary headers  */
  32.  
  33. #define MAX_CUST 100
  34.  
  35. typedef struct cust
  36. {
  37.   int status;
  38.   int cust_no;
  39.   char business[34];
  40.   char name[34];
  41.   char addr[34];
  42.   char city[34];
  43.   char state[4];
  44.   char zip[10];
  45.   char phone[16];
  46.   char fax[16];
  47.   char date[10];
  48.   char memo[34];
  49.   char unused[26];                                /* round out to 256 bytes */
  50. } CUST;
  51.  
  52. /*----------------------- global window variables --------------------------*/
  53. WINDOW   Desk_wn, Window1;
  54. CUST Customers[MAX_CUST];
  55. char Fname[33];
  56.  
  57. MENU    Top_menu, *Top_mnp = &Top_menu;
  58. MENU    Files_menu, Edit_menu, Print_menu;
  59. MENU    *Drop_mnps[3];
  60.  
  61. PRINT   Print;
  62.  
  63. /*-------------------------------- prototypes ------------------------------*/
  64. int disp_time(void);
  65. void disp_cust(CUST *cp, WINDOW *wnp);
  66. int file_load(CUST *customers);
  67. int file_save(CUST *customers);
  68. int get_fname(char *fname);
  69. void print_cust(CUST *cp, PRINT *p);
  70.  
  71. /*********/
  72. /* ~main */
  73. /*       ********************************************************************/
  74. /*  Demonstrate data entry capability...                                    */
  75. /****************************************************************************/
  76. int main()
  77. {
  78.   int i, ret_val, cust = 0, end_flag = 0, print_stat = 0;
  79.   WINDOW *wnp;
  80.   CUST *cp;
  81.   uchar back_att  = (LIGHTGRAY << 4) | BLACK,
  82.         bdr_att   = (LIGHTGRAY << 4) | BLACK,
  83.         csr_att   = (CYAN << 4) | YELLOW,
  84.         first_att = (LIGHTGRAY << 4) | RED;
  85.   
  86.   wnp = &Window1;                         /* set local window pointer       */
  87.   init_video(80, 25);                     /* init video for 80 x 25 screen  */
  88.   init_clock(0x3333);                     /* init clock irq at 91 tics/sec  */
  89.  
  90.   wn_create(0, 0, V_cols-1, V_rows-1, NO_BDR, WN_NORMAL, &Desk_wn);
  91.   link_window(&Desk_wn);
  92.  
  93.   /*------------------------ create the menu system ------------------------*/
  94.   Drop_mnps[0] = &Files_menu;
  95.   Drop_mnps[1] = &Edit_menu;
  96.   Drop_mnps[2] = &Print_menu;
  97.  
  98.   menu_create(0, 0, V_cols - 1, 0, M_HORIZONTAL,
  99.               back_att, bdr_att, csr_att, first_att,
  100.               NO_BDR, WN_NORMAL, Top_mnp);
  101.   item_add( "   Files   ", 1, 3, &Top_menu );
  102.   item_add( "   Edit    ", 2, 3, &Top_menu );
  103.   item_add( "   Print   ", 8, 3, &Top_menu );
  104.  
  105.   menu_create(0, 1, 14, 5, M_VERTICAL,
  106.     back_att, bdr_att, csr_att, first_att,
  107.     SGL_BDR, WN_NORMAL, Drop_mnps[0]);
  108.   item_add( " Load File", 4, 1, &Files_menu );
  109.   item_add( " Save File", 5, 1, &Files_menu );
  110.   item_add( "   Quit   ", 3, 3, &Files_menu );
  111.  
  112.   menu_create(11, 1, 32, 4, M_VERTICAL,
  113.     back_att, bdr_att, csr_att, first_att,
  114.     SGL_BDR, WN_NORMAL, Drop_mnps[1]);
  115.   item_add( " Clear Current", 6, 7, &Edit_menu );
  116.   item_add( " Clear All    ", 7, 7, &Edit_menu );
  117.  
  118.   menu_create(22, 1, 43, 4, M_VERTICAL,
  119.     back_att, bdr_att, csr_att, first_att,
  120.     SGL_BDR, WN_NORMAL, Drop_mnps[2]);
  121.   item_add( " Print Current", 9, 7, &Print_menu );
  122.   item_add( " Print All    ", 10, 7, &Print_menu );
  123.  
  124.   set_idle_func(disp_time);               /* set background clock function  */
  125.  
  126.   wn_create(5, 5, 75, 20, SLD_BDR, WN_POPUP, wnp);
  127.   wn_color(YELLOW, BLUE, wnp);            /* change the window colors       */
  128.   wn_bdr_color(WHITE, BLUE, wnp);         /* change the border's colors     */
  129.   link_window(wnp);
  130.  
  131.   /*------------- initialize first customer as EnQue Software --------------*/
  132.   cp = &Customers[0];
  133.   strcpy(cp->business, "EnQue Software");
  134.   strcpy(cp->name, "Kevin Huck & Boyd Gafford");
  135.   strcpy(cp->addr, "Rt. 1 Box 116C");
  136.   strcpy(cp->city, "Pleasant Hill");
  137.   strcpy(cp->state, "MO");
  138.   strcpy(cp->zip, "64080");
  139.   strcpy(cp->phone, "(816)987-2515");
  140.   strcpy(cp->fax, "(816)987-2515");
  141.   strcpy(cp->date, "09/11/92");
  142.   strcpy(cp->memo, "BBS 816-358-8990");
  143.  
  144.   /*------------------------ initialize the printer ------------------------*/
  145.   if( init_printer("LPT1", NULL, 2048L, 2048L, &Print) )
  146.     print_stat = 1;
  147.  
  148.   menu_set(Top_mnp);
  149.   while(!end_flag)
  150.   {
  151.     cp = &Customers[cust];
  152.     mv_cs(1,1, wnp);
  153.     wn_printf(wnp, "Customer:%3d", cust+1);
  154.     wn_plst(CENTERED, 3, "Use cursor keypad to select customer", &Desk_wn);
  155.     disp_cust(cp, wnp);
  156.     wait_event();
  157.     switch(Event.key)
  158.     {
  159.       /*------------------------- process menus ----------------------------*/
  160.       case KEY_ALT_Q:                                       /* quit program */
  161.         end_flag = 1;
  162.         break;
  163.       case KEY_ALT_F: case KEY_ALT_E: case KEY_ALT_P:
  164.         m_show();
  165.         if( Event.key == KEY_ALT_F )
  166.           ret_val = menu_system_ll(&Top_menu,&Drop_mnps[0],0,'F',M_EXIT_ON_ESC);
  167.         else if( Event.key == KEY_ALT_E )
  168.           ret_val = menu_system_ll(&Top_menu,&Drop_mnps[0],0,'E',M_EXIT_ON_ESC);
  169.         else
  170.           ret_val = menu_system_ll(&Top_menu,&Drop_mnps[0],0,'P',M_EXIT_ON_ESC);
  171.         switch( ret_val )
  172.         {
  173.           case 3:                                           /* quit program */
  174.             end_flag = 1;
  175.             break;
  176.           case 4:                                           /* load file    */
  177.             file_load(Customers);
  178.             break;
  179.           case 5:                                           /* save file    */
  180.             file_save(Customers);
  181.             break;
  182.           case 6:                                           /* clear one    */
  183.             setmem(cp, sizeof(CUST), 0);
  184.             break;
  185.           case 7:                                           /* clear all    */
  186.             setmem(Customers, sizeof(Customers), 0);
  187.             break;
  188.           case 9:                                           /* print one    */
  189.             if( print_stat )
  190.               print_cust(cp, &Print);
  191.             break;
  192.           case 10:                                          /* print all    */
  193.             if( print_stat )
  194.               for( i = 0; i < MAX_CUST; i++ )
  195.                 if( strlen(Customers[i].name) )             /* not empty?   */
  196.                   print_cust(&Customers[i], &Print);
  197.             break;
  198.         }
  199.         break;
  200.       /*---------------------- process cursor keys -------------------------*/
  201.       case KEY_HOME:
  202.         cust = 0;
  203.         break; 
  204.       case KE